﻿#include "Line.h"
#include "MathVector2d.h"

  //if lines are parallel returns true ,else returns false
bool are_Parallel( const Line& a, const Line& b ){
    if( cos( a.get_vector(), b.get_vector() ) == 1 ||
        cos( a.get_vector(), b.get_vector() ) == -1 ){ return true;
    }else{
        return false;
    }
}

  //checks if dot belongs to line
bool checkDotInLine( const Line& a, const float x, const float y ){
    const float k = (a.get_vector() ).get_y() / (a.get_vector() ).get_x() ;
    const float b = a.get_y() - k * a.get_x();
    if( ( y - k * x - b ) == 0 ){ return true; }
    else{ return false; }
}

  //returns radius-vector to point at which lines cross at
MathVector2d<float> getLineIntersection( const Line& a, const Line& b ){
    const float k1 = (a.get_vector() ).get_y() / (a.get_vector() ).get_x() ;
    const float b1 = a.get_y() - k1 * a.get_x();
    const float k2 = (b.get_vector() ).get_y() / (b.get_vector() ).get_x() ;
    const float b2 = b.get_y() - k2 * b.get_x();
    const float y = ( ( k2 * b1 - k1 * b2 ) / ( k2 - k1 ) );
    const float x = ( ( y - b2 ) / k2 );
    return MathVector2d<float>( x, y );
}
